<?php

namespace app\advertiser\controller;

use app\advertiser\service\AdTaskService;
use app\BaseController;
use think\facade\Request;
use think\response\Json;

/**
 * 微信公众号推广任务
 */
class AdOfficialAccountTask extends BaseController
{
    /**
     * 公众号
     * @var int
     */
    private int $type = 1;

    /**
     * 公众号推广任务列表
     * @param AdTaskService $adTaskService
     * @return Json
     */
    public function list(AdTaskService $adTaskService): Json
    {
        $params['page'] = Request::param('page/d', 1);
        $params['limit'] = Request::param('limit/d', 10);
        $params['task_name'] = Request::param('task_name/s');
        $params['start_time'] = Request::param('start_time/d', 0);
        $params['end_time'] = Request::param('end_time/d', 0);
        return $adTaskService->list($params, $this->type);
    }

    /**
     * 公众号推广任务增加
     * @param AdTaskService $adTaskService
     * @return Json
     */
    public function add(AdTaskService $adTaskService): Json
    {
        $params['matter_id'] = Request::param('matter_id/d');
        $params['task_name'] = Request::param('task_name/s');
        $params['task_desc'] = Request::param('task_desc/s');
        $params['single_price'] = Request::param('single_price');
        $params['daily_limit'] = Request::param('daily_limit');
        $params['total_limit'] = Request::param('total_limit');
        $params['contact'] = Request::param('contact/s');
        $params['contact_tel'] = Request::param('contact_tel/s');
        $params['is_auto_online'] = Request::param('is_auto_online/d', 0);
        $params['sex'] = Request::param('sex/d', 0);
        $params['device_type'] = Request::param('device_type/a', []);
        $params['industry'] = Request::param('industry/d', 0);
        $params['location'] = Request::param('location/a', []);
        $params['region'] = Request::param('region/d', 0);
        $params['remark'] = Request::param('remark/s', '');
        return $adTaskService->add($params, $this->type);
    }

    /**
     * 公众号推广任务编辑
     * @param AdTaskService $adTaskService
     * @return Json
     */
    public function edit(AdTaskService $adTaskService): Json
    {
        $params['id'] = Request::param('id/d');
        $params['matter_id'] = Request::param('matter_id/d');
        $params['task_name'] = Request::param('task_name/s');
        $params['task_desc'] = Request::param('task_desc/s');
        $params['single_price'] = Request::param('single_price');
        $params['daily_limit'] = Request::param('daily_limit');
        $params['total_limit'] = Request::param('total_limit');
        $params['contact'] = Request::param('contact/s');
        $params['contact_tel'] = Request::param('contact_tel/s');
        $params['is_auto_online'] = Request::param('is_auto_online/d', 0);
        $params['sex'] = Request::param('sex/d', 0);
        $params['device_type'] = Request::param('device_type/a', []);
        $params['industry'] = Request::param('industry/d', 0);
        $params['location'] = Request::param('location/a', []);
        $params['region'] = Request::param('region/d', 0);
        $params['remark'] = Request::param('remark/s', '');
        return $adTaskService->edit($params, $this->type);
    }

    /**
     * 公众号推广任务删除
     * @param AdTaskService $adTaskService
     * @return Json
     */
    public function del(AdTaskService $adTaskService): Json
    {
        $id = Request::param('id/d');
        return $adTaskService->del($id, $this->type);
    }

    /**
     * 公众号推广任务提交审核
     * @param AdTaskService $adTaskService
     * @return Json
     */
    public function review(AdTaskService $adTaskService): Json
    {
        $id = Request::param('id/d');
        return $adTaskService->review($id, $this->type);
    }

    /**
     * 公众号推广任务上下架
     * @param AdTaskService $adTaskService
     * @return Json
     */
    public function shelves(AdTaskService $adTaskService): Json
    {
        $id = Request::param('id/d');
        $status = Request::param('status/d');
        return $adTaskService->shelves($id, $status, $this->type);
    }


}